
#include "mainwindow.h"

#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QMainWindow>

#include <FlatpakManager.h>
#include <QCommandLineParser>

void moveCenter(QWidget &wm) {
    QDesktopWidget *desktop = QApplication::desktop();
    wm.move((desktop->width() - wm.width()) /2,(desktop->height() - wm.height()) /2);
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setApplicationName("Flatpak管理器 - v0.1");
    MainWindow wm;
    wm.show();

    moveCenter(wm);

    QCommandLineParser parser;
    parser.setApplicationDescription("Flatpak GUI Manager.");
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument("flatpakrepo", QApplication::translate("main", ".flatpakrepo file path."), "*.flatpakrepo");
    parser.process(a);
   
    auto file_list =  parser.positionalArguments();

    qDebug() << "file_list:" << file_list.size();
    if (file_list.size()) {
        QMetaObject::invokeMethod(&wm, "onFlatpakrepoSelected", Qt::QueuedConnection, Q_ARG(QString, file_list[0]));
    }

    return a.exec();
}
